package tianwang.test;

import java.util.ArrayList;
import java.util.List;

import tianwang.biz.ArticleGetter;
import tianwang.biz.CAStyleGenerateAndSave;
import tianwang.biz.stat.SentenceAverageLength;
import tianwang.biz.stat.SentenceLongNumberCollecter;
import tianwang.biz.stat.SentenceShortNumberCollecter;
import tianwang.biz.stat.SentenceStandardDeviation;
import tianwang.dao.IBatisDao;
import tianwang.model.AticleModel;
import tianwang.model.CAFile;
import tianwang.service.stat.ArticleStat;
import tianwang.services.collect.CollectResult;
import tianwang.services.collect.Collecter;
import tianwang.util.FileUtil;

/**
 * 对每个文件进行分析
 * 分析语料的各个属性
 */
public class AnalysisEachFile {
	private ArticleGetter articleBiz = new ArticleGetter(); 
	
	private IBatisDao dao = null;
	
	public static void main(String[] args) throws Exception {
		AnalysisEachFile main = new AnalysisEachFile();
		main.dao = new IBatisDao();
		int count = 1;
		
		//调试
//		if(true){
//			CAFile caFile =  new CAFile();
//			caFile.setId(721);
//			caFile.setPath("magazine\\and A Contest to Capture Democracy on Video (2).txt");
//			main.dealEachFile(caFile);
//			return;
//		}
		
		//跳过id=720的文件前面的部分
//		main.articleBiz.recordStartNum = 486;
		
		List<CAFile> fileList = null;
		while((fileList = main.articleBiz.getFileList()) != null)
		{
			for(CAFile caFile:fileList){
				main.dealEachFile(caFile);
			}
		}
	
		System.out.println("OVER!");
	}
	
	public void dealEachFile(CAFile caFile) throws Exception{
		
		String content = FileUtil.getContent(caFile.getFile());
		
		AticleModel model = new AticleModel();
		model.setFile(caFile);
		
		ArticleStat stat = new ArticleStat();
		
		stat.setAticleModel(model);
		List<Collecter<CollectResult>> collecters = new ArrayList<Collecter<CollectResult>>();
		
//		collecters.add(new WordsAvgLengthCollecter());//平均词长
//		collecters.add(new WordsMedianFreqCollecter());//词频中位数
//		collecters.add(new WordsDensityCollecter());//词汇密度
//		collecters.add(new WordsCommonICollecter());//第一类词汇
//		collecters.add(new WordsCommonIICollecter());//第二类词汇
//		collecters.add(new WordsVariationCollecter());//词汇多样性
		
		collecters.add(new SentenceShortNumberCollecter());
		collecters.add(new SentenceLongNumberCollecter());
		collecters.add(new SentenceStandardDeviation());
		collecters.add(new SentenceAverageLength());
		
		stat.setCollecters(collecters);
		stat.doCollect();
		
		/*
		 * 输出结果
		 */
		List<CollectResult> re = stat.getResult();
		
//		/*
//		 * 生成保存Lexical表相关的处理对象
//		 */
//		CALexicalGenerateAndSave lexicalGenerator = new CALexicalGenerateAndSave(this.dao);
//		lexicalGenerator.setCaFile(caFile);
//		lexicalGenerator.generateAndSave(re);
//		
		/*
		 * 成成并保存Style表的相关的处理对象
		 */
		CAStyleGenerateAndSave styleGenerator = new CAStyleGenerateAndSave(this.dao);
		styleGenerator.setCaFile(caFile);
		styleGenerator.generateAndSave(re);
		
		System.out.println("计算完： " +caFile.getPath());
	}

}
